#ifndef B_PHYSICS_RAY_CALLBACK_H_
#define B_PHYSICS_RAY_CALLBACK_H_

#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"

// Simply does all the stuff a normal BulletClosestRayCallBack does,
// but stores the triangle index which is usually scrapped

struct MyRayCallBack : public btCollisionWorld::ClosestRayResultCallback
{
    //This is the only thing I need added to the default behaviour
    int m_triangleIndex;
    
    //Call the base classes default CTR, initialise our index to 0
    MyRayCallBack (const btVector3 & rayFrom,const btVector3 & rayTo)
        : btCollisionWorld::ClosestRayResultCallback(rayFrom, rayTo),
        m_triangleIndex(0) {}

    //Virtual DTR
    virtual ~MyRayCallBack()
    {
    }

    //Now our implementation stores a little bit more data than the base class,
    //and then calls the base class implementation
    virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult & rayResult, bool normalInWorldSpace)
    {
        //simply store the index, 
        if (rayResult.m_localShapeInfo)
        {
            m_triangleIndex = rayResult.m_localShapeInfo->m_triangleIndex;
        } 
        else 
        {
            m_triangleIndex = 0;
        }
        //and then call the base classes implementation! 
        //Very similar to UnrealScript :-)
        return ClosestRayResultCallback::addSingleResult(rayResult,normalInWorldSpace);
    }
};
#endif